﻿//编写面向对象程序实现长方形、正方形、圆形等形
//状的类。
//1. 每个形状类都能计算面积、判断形状是否合法。
//请尝试合理使用接口/抽象类、属性来实现。
//2. 随机创建10个形状对象，计算这些对象的面积之和
using System;
namespace Secondhomework
{
    interface IGetArea//接口
    {
        double GetArea();
    }
    enum ShapeType//枚举类型
    {
        Rectangle,
        Square,
        Circle
    }

    class Rectangle : IGetArea//长方形类
    {
        private readonly double width;
        private readonly double height;
        public Rectangle(double width, double height)=>     //主构造函数
            (this.height, this.width) = (height, width);
        public double GetArea()//计算面积方法
        {
            return width * height;
        }
    }
    class Square : IGetArea//正方形类
    {
        private readonly double side;
        public Square(double side)=>
            this.side = side;
        
        public double GetArea()
        {
            return side * side;
        }
    }
    class Circle : IGetArea//圆形类
    {
        private readonly double radius;
        public Circle(double radius)=>
            this.radius = radius;
       
        public double GetArea()
        {
            return Math.PI * radius * radius;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Random random = new Random();
            double sum = 0;
            for (int i = 0; i < 10; i++)
            {
                ShapeType shapeType = (ShapeType)random.Next(3);//随机生成三种形状  
                switch (shapeType)
                {
                    case ShapeType.Rectangle:
                        Rectangle rectangle = new Rectangle(random.NextDouble()*9+1, random.Next(1, 10));//随机生成长方形,宽高范围1-10
                        Console.WriteLine("Rectangle  area = {0}",rectangle.GetArea());
                        sum += rectangle.GetArea();
                        break;
                    case ShapeType.Square:
                        Square square = new Square(random.NextDouble() * 9 + 1);//随机生成正方形,边长范围1-10
                        Console.WriteLine("Square  area = {0}",square.GetArea());
                        sum += square.GetArea();
                        break;
                    case ShapeType.Circle:
                        Circle circle = new Circle(random.NextDouble() * 9 + 1);//随机生成圆形,半径范围1-10
                        Console.WriteLine("Circle  area = {0}",circle.GetArea());
                        sum += circle.GetArea();
                        break;
                }
            }
            Console.WriteLine("Sum of areas = {0}", sum);
            Console.ReadKey();
        }
    }
}